﻿using System;

using System.Text;
using IAM.Interface.Model.Interface;
using System.Reflection;
using System.Web;

namespace IAM.Interface.Model
{
    /// <summary>
    /// 人员账号信息
    /// </summary>
    [Serializable]
    public class AccountInfo : AbstractConvertObject,IConvertXml
    {
        #region 属性
        private string _hriseid = "";//HRISEID 
        private string _adaccount = "";//ADAccount 
        private string _cslaccount = "";//CSLAccount 
        private string _cilx500= "";//CILX500 
        private string _upi = "";//UPI 
        private string _appaccount = "";//AppAccount 
        private string _iamid = "";
        private string _password = "";

        
        /// <summary>
        /// 人员在HRIS中的EmployeeID
        /// </summary>
        public string HRISEID
        {
            set
            {
                _hriseid = value;
            }
            get
            {
                return _hriseid;
            }
        }
        /// <summary>
        /// 人员在AD账号，包含域名定义
        /// </summary>
        public string ADAccount
        {
            set
            {
                _adaccount = value;
            }
            get
            {
                return _adaccount;
            }
        }
        /// <summary>
        /// 人员在X500中的CSL信息
        /// </summary>
        public string CSLAccount
        {
            set
            {
                _cslaccount = value;
            }
            get
            {
                return _cslaccount;
            }
        }
        /// <summary>
        /// 人员在X500中的CIL信息
        /// </summary>
        public string CILX500
        {
            set
            {
                _cilx500 = value;
            }
            get
            {
                return _cilx500;
            }
        }
        /// <summary>
        /// 人员的UPI信息
        /// </summary>
        public string UPI
        {
            set
            {
                _upi = value;
            }
            get
            {
                return _upi;
            }
        }
        /// <summary>
        /// 人员在本应用中的账号信息
        /// </summary>
        public string AppAccount
        {
            set
            {
                _appaccount = value;
            }
            get
            {
                return _appaccount;
            }
        }
        /// <summary>
        /// 人员在IAM中的主键
        /// </summary>
        public string IAMID
        {
            get
            {
                return _iamid;
            }
            set
            {
                _iamid = value;
            }
        }
        /// <summary>
        /// 密码
        /// </summary>
        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }
        #endregion
        #region IConvertXml

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append(" <AccountInfo>");
                _xml.Append(" <HRISEID>" + IAM.Interface.Common.EnDeCoding.Encode(this.HRISEID )+ "</HRISEID>");
                _xml.Append(" <ADAccount>" + IAM.Interface.Common.EnDeCoding.Encode(this.ADAccount) + "</ADAccount>");
                _xml.Append(" <CSLAccount>" +IAM.Interface.Common.EnDeCoding.Encode( this.CSLAccount )+ "</CSLAccount>");
                _xml.Append(" <CILX500>" + IAM.Interface.Common.EnDeCoding.Encode(this.CILX500) + "</CILX500>");
                _xml.Append(" <UPI>" + IAM.Interface.Common.EnDeCoding.Encode(this.UPI) + "</UPI>");
                _xml.Append(" <AppAccount>" + IAM.Interface.Common.EnDeCoding.Encode(this.AppAccount )+ "</AppAccount>");
                _xml.Append(" <IAMID>" + IAM.Interface.Common.EnDeCoding.Encode(this.IAMID )+ "</IAMID>");
                //主要是为了和老版本的兼容
                try
                {
                    _xml.Append(" <Password>" + IAM.Interface.Common.EnDeCoding.Encode(this.Password) + "</Password>");
                }
                catch 
                { }
                return _xml.ToString();
            }


        }

        public string XMLFinis
        {
            get
            {
                return "</AccountInfo>";
            }
        }
        public string XML
        {
            get
            {
                return XMLBoday + XMLFinis;
            }
        }
        #endregion
        #region AbstractConvertObject
        public override object ConvertToObject()
        {
            //1.获取当前结点
            this.HRISEID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("HRISEID").InnerText);
            this.ADAccount = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("ADAccount").InnerText);
            this.CSLAccount = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("CSLAccount").InnerText);
            this.CILX500 = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("CILX500").InnerText);
            this.UPI = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("UPI").InnerText);
            this.AppAccount = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("AppAccount").InnerText);
            //因为是后添加的属性，避免之前版本的的解析错误
            try
            {
                this.IAMID = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("IAMID").InnerText);
            }
            catch
            {
                this.IAMID = "";
            }
            try
            {
                this.Password = IAM.Interface.Common.EnDeCoding.Decode(this.CurrentXmlNode.SelectSingleNode("Password").InnerText);
            }
            catch
            {
                this.Password = "";
            }
            return this;
        }
        #endregion
        #region 重写Equals
        /// <summary>
        /// 确定指定的 AccountInfo 对象是否等效于当前 AccountInfo
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            AccountInfo ai = null;
            try
            {
                ai = (AccountInfo)obj;
            }
            catch
            {
                return false;
            }
            bool result = true;

            if (this.HRISEID != ai.HRISEID)
            {
                result = false;
            }
            else if (this.ADAccount != ai.ADAccount)
            {
                result = false;
            }
            else if (this.CSLAccount != ai.CSLAccount)
            {
                result = false;
            }
            else if (this.CILX500 != ai.CILX500)
            {
                result = false;
            }
            else if (this.UPI != ai.UPI)
            {
                result = false;
            }
            else if (this.AppAccount != ai.AppAccount)
            {
                result = false;
            }
            else if (this.IAMID != ai.IAMID)
            {
                result = false;
            }
            return result;
        }

        #endregion
        #region 重写GetHashCode
        /// <summary>
        /// 哈希函数
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            int result = 1;
            PropertyInfo[] pi = this.GetType().GetProperties();
            foreach (PropertyInfo onofpi in pi)
            {
                result = result + onofpi.GetHashCode();
            }
            return result;
        }
        #endregion
    }

}
